package com.igoal.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "message")
public class Message extends BaseObject implements Serializable, Audit {
	private static final long serialVersionUID = -4527905586532627088L;
	private Long id;
	private User to;
	private User from;
	private boolean messageStatus;
	private int priority;
	private String subject;
	private String body;
	private Date createDate;
//	private Date updateDate;
	private DataStatus status;

	public Message() {
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "to_id", nullable = false)
	public User getTo() {
		return this.to;
	}

	public void setTo(User user) {
		this.to = user;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "from_id", nullable = false)
	public User getFrom() {
		return this.from;
	}

	public void setFrom(User user) {
		this.from = user;
	}

	@Column(name = "message_status", nullable = false)
	public boolean isMessageStatus() {
		return this.messageStatus;
	}

	public void setMessageStatus(boolean messageStatus) {
		this.messageStatus = messageStatus;
	}

	@Column(name = "priority", nullable = false)
	public int getPriority() {
		return this.priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	@Column(name = "subject", nullable = false, length = 65535)
	public String getSubject() {
		return this.subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@Column(name = "body", nullable = false, length = 65535)
	public String getBody() {
		return this.body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "cdate", nullable = false, length = 19)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date date) {
		this.createDate = date;
	}

	@Enumerated(EnumType.STRING)
	@Column(name = "status", nullable = false, length = 50)
	public DataStatus getStatus() {
		return this.status;
	}

	public void setStatus(DataStatus status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return "Message ["+this.subject+"] from "+this.from+" to "+this.to;
	}

	@Override
	public boolean equals(Object o) {
		if(o == null) return false;
		Message m = (Message) o;
		return m.getId() == this.id;
	}

	@Override
	public int hashCode() {
		return this.id.hashCode();
	}

	@Transient
	public Date getUpdateDate() {
		return null;
	}

	@Transient
	public void setUpdateDate(Date date) {
		return;
	}
}
